package objs;

import service.Play;

import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class Meobj extends Pojo{
    public static int meState=0;
    private int bombNum=0;
    public static int launchState=0;
    public Meobj(Image image, int x, int y, int width, int height, double speed, Play frame) {
        super(image, x, y, width, height, speed, frame);
        this.frame.addMouseMotionListener(new MouseAdapter() {
            @Override
            public void mouseMoved(MouseEvent e) {
                Meobj.super.x=e.getX()-51;
                Meobj.super.y=e.getY()-63;
            }
        });
        this.frame.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if(e.getButton()==1&&bombNum>0) {
                    bombNum--;
                    launchState=1;
                    System.out.println("发射！  剩余：" + bombNum);
                }
            }
        });
    }

    public Meobj() {}

    @Override
    public void paintSelf(Graphics gImage) {

//        if(this.getRec().intersects(this.frame.bossobj.getRec())){
//            Play.state=3;
//        }
        for(Bossobj bossobj:Play.bossobjList)
        if(this.getRec().intersects(bossobj.getRec())){
            Play.state=3;
        }

        if(Play.state==1) {
            switch (meState) {
                case 0:
                    gImage.drawImage(Play.me1, x, y, width, height, null);
                    meState = 1;
                    break;
                case 1:
                    gImage.drawImage(Play.me2, x, y, width, height, null);
                    meState = 0;
                    break;
                default:
            }
        }
        //不能使用foreach循环
        for(int i=0;i<Play.bombobjList.size();i++){
            if(this.getRec().intersects(Play.bombobjList.get(i).getRec())){
                Play.removeList.add(Play.bombobjList.get(i));
                Play.bombobjList.remove(Play.bombobjList.get(i));
                bombNum++;
            }
        }


    }
}
